package keye.document_manage.gui;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import keye.document_manage.entity.Page;

public class PagingPanel extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel current;
	private JLabel total;
	private JButton nextB;
	private JButton previousB;
	private JButton goButton;
	private JTextField goValue;
	public JTextField getGoValue() {
		return goValue;
	}

	public void setGoValue(JTextField goValue) {
		this.goValue = goValue;
	}

	private Page page;
	private String tableName;

	public PagingPanel() {
		this.setLayout(new FlowLayout());
		current = new JLabel("第 0 页");
		this.add(current);
		
		previousB = new JButton("上一页");
		previousB.setActionCommand("previous");
		this.add(previousB);
		
		nextB = new JButton("下一页");
		nextB.setActionCommand("next");
		this.add(nextB);
		
		total = new JLabel("共 0 页 共 0 条");
		this.add(total);
		
		JLabel label = new JLabel("跳到");
		this.add(label);
		goValue = new JTextField(3);
		this.add(goValue);
		JLabel label_1 = new JLabel("页");
		this.add(label_1);
		goButton = new JButton("确定");
		goButton.setActionCommand("go");
		this.add(goButton);
		previousB.setEnabled(false);
		nextB.setEnabled(false);
		goButton.setEnabled(false);
	}
	
	
	public void refresh(){
		long currentN = page.getCurrentPage();
		long totalN = page.getTotalPage();
		if(currentN <= 1){
			previousB.setEnabled(false);
		}else {
			previousB.setEnabled(true);
		}
		if(currentN >= totalN){
			nextB.setEnabled(false);
		}else{
			nextB.setEnabled(true);
		}
		goButton.setEnabled(true);
		current.setText("第 "+currentN+" 页");
		total.setText("共 "+totalN+" 页 共 "+page.getTotalNumber()+" 条");
		
	}

	
	public JButton getPreviousB() {
		return previousB;
	}

	public void setPreviousB(JButton previousB) {
		this.previousB = previousB;
	}

	public JButton getNextB() {
		return nextB;
	}

	public void setNextB(JButton nextB) {
		this.nextB = nextB;
	}
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
		refresh();
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public JTextField getGo() {
		return goValue;
	}

	public void setGo(JTextField go) {
		this.goValue = go;
	}

	public JButton getGoButton() {
		return goButton;
	}

	public void setGoButton(JButton goButton) {
		this.goButton = goButton;
	}

	
}
